<?php
/**
 * abstract GetBookBaseInfo 获取图书基本信息
 * author:彭荣贵
 * date ：2013/10/20
 */

require_once 'sys_fns.php';
require_once './model/BookBaseEntity.php';

abstract  class GetBookBaseInfo
{
	
	/**
	 * 当前网页html信息
	 * @var string
	 */
	protected $pagecontent;
	
	/**
	 * 一个书目的html信息
	 * @var string
	 */
	protected $onecontent;
	
	/**
	 * 包含书本实体的 数组
	 * @var array
	 */
	protected $book_list= array();
	
	/**
	 * 图书主页url
	 * @var string
	 */
	protected $url;
	
	/**
	 * 网站主页
	 * @var string
	 */
	protected $web_url;
	
	/**
	 * 搜索词
	 * @var string
	 */
	protected $search_key;
	
	/**
	 * 设置url
	 * @param string $url
	 */
	function __construct($url,$web_url=null,$search_key=NULL)
	{
		$this->url = $url;
		$this->search_key = $search_key;
		$this->web_url    =$web_url;
	}
	
	/**
	 * 获取主页内容
	 */
	function getIndexPageContent()
	{
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $this->url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_TIMEOUT, 0);
		$this->pagecontent = curl_exec($ch);
	}
	
	/**
	 * 设定书名
	 * @param BookBaseEntity $book
	 * @param string $name
	 */
 	function setBookName(BookBaseEntity $book,$name)
 	{
 		//将引号替换掉
 		$name = replaceQuot($name);
 		$book->_BOOKNAME = $name;
 	}
 	
 	/**
 	 * 设定作者
 	 * @param BookBaseEntity $book
 	 * @param string $author
 	 */
 	function setBookAuthor(BookBaseEntity $book,$author)
 	{
 		//替换引号
 		$author = replaceQuot($author);
 		$book->_AUTHOR = $author;
 	}
 	
 	/**
 	 * 设定价格
 	 * @param BookBaseEntity $book
 	 * @param float $price
 	 */
 	function setBookPrice(BookBaseEntity $book,$price)
 	{
 		$book->_PRICE = $price;
 	}
 	
 	/**
 	 * 设定图书折扣价
 	 * @param BookBaseEntity $book
 	 * @param string $discount_price
 	 */
 	function setBookDiscountPrice(BookBaseEntity $book,$discount_price)
 	{
 		$book->_DISCOUNT_PRICE = $discount_price;
 	}
 	
 	
 	/**
 	 * 设定折扣
 	 * @param BookBaseEntity $book
 	 * @param float $discount
 	 */
 	function setBookDiscount(BookBaseEntity $book,$discount)
 	{
 		$book->_DISCOUNT = $discount;
 	}
 	
 	/**
 	 * 设定评论人数
 	 * @param BookBaseEntity $book
 	 * @param int $nums
 	 */
 	function setBookCommentNums(BookBaseEntity $book,$nums)
 	{
 		$book->_COMMENT_NUMS = intval($nums);
 	}
 	/**
 	 * 设定平装否
 	 * @param BookBaseEntity $book
 	 * @param string $pingzhuang
 	 */
 	function setBookPingzhuang(BookBaseEntity $book,$pingzhuang)
 	{
 		$book->_PINGZHUANG = $pingzhuang;
 	}
 	
 	/**
 	 * 设定图书图片url
 	 * @param BookBaseEntity $book
 	 * @param string $img_url
 	 */
 	function setBookImgUrl(BookBaseEntity $book,$img_url)
 	{
 		$book->_IMG_URL = $img_url;
 	}
 	
 	/**
 	 * 设定图书详细信息url
 	 * @param BookBaseEntity $book
 	 * @param unknown_type $detail_url
 	 */
 	function setBookDetailUrl(BookBaseEntity $book,$detail_url)
 	{
 		$book->_DETAIL_URL = $detail_url;
 	}
 	
 	
 	/**
 	 * 设定图书简介
 	 * @param BookBaseEntity $book
 	 * @param string $intro
 	 */
 	function setBookIntroduction(BookBaseEntity $book,$intro)
 	{
 		//替换引号 
 		$intro = replaceQuot($intro);
 		$book->_INTRODUCTION = $intro;
 	}
 	
 	
 	/**
 	 * 设定付款方式
 	 * @param BookBaseEntity $book
 	 * @param string $cost_way
 	 */
 	function setBookCostWay(BookBaseEntity $book,$cost_way)
 	{
 		$book->_COSTWAY = $cost_way;
 	}
 	
 	/**
 	 * 设定评论信息url
 	 * @param BookBaseEntity $book
 	 * @param string $comment_url
 	 */
 	function setBookCommentUrl(BookBaseEntity $book,$comment_url)
 	{
 		$book->_COMMENT_URL = $comment_url;
 	}
 	
 	/**
 	 * 设定图书来自哪个网站
 	 * @param BookBaseEntity $book
 	 * @param string $from
 	 */
 	function setBookFrom(BookBaseEntity $book,$from)
 	{
 		$book->_FROM = $from;
 	}
 	
 	/**
 	 * 设定图书评分
 	 * @param BookBaseEntity $book
 	 * @param float $grade
 	 */
 	function setBookGrade(BookBaseEntity $book,$grade)
 	{
 		$book->_GRADE = floatval($grade);
 	}
 	
 	/**
 	 * 设定图书出版社
 	 * @param BookBaseEntity $book
 	 * @param string $publishment
 	 */
 	function setBookPublishment(BookBaseEntity $book,$publishment)
 	{
 		//替换引号
 		$publishment = replaceQuot($publishment);
 		$book->_PUBLISHMENT = $publishment;
 	}
 	
 	/**
 	 * 返回提取的图书数组
 	 * @return multitype:
 	 */
 	function returnList()
 	{
 		return $this->book_list;
 	}
 	
 	/**
 	 * 添加一个图书实体到数组中
 	 * @param BookBaseEntity $book
 	 */
 	function addBookToList(BookBaseEntity $book)
 	{
 		$this->book_list[] = $book;
 	}
 	
 	
 	/**
 	 * 获取搜索页的信息
 	 */
 	abstract function getSearchPageContent();
 	
 	/**
 	 * 获取设定图书所有信息
 	 */
 	abstract function getBooks();
 	
 	/**
 	 * 设定图书来自标记
 	 */
 	abstract  function setBookFromTag(BookBaseEntity $book);
 	
 	/**
 	 * 设定最最首页
 	 * @param BookBaseEntity $book
 	 * @param string $url
 	 */
 	function  setBookWebUrl(BookBaseEntity $book)
 	{
 		$book->_WEB_URL =$this->web_url;
 	}
 	
 	/**
 	 * 将对象json
 	 * @param BookBaseEntity $book
 	 */
 	function bookToJson(BookBaseEntity $book)
 	{
 		$book->_JSON_STR = json_encode($book);
 	}
}
?>